data_list=["苦瓜","黄瓜","黄豆","青瓜","绿豆","黄鳝"]
data_list=[data for data in data_list if "黄" not in data]
print("我是过滤出来的数据:",data_list)
#我是过滤出来的数据: ['苦瓜', '青瓜', '绿豆']
data_list=[(x,y)for x in ['青椒','辣椒'] for y in ['猪肉','牛肉'] if "辣" not in x and "牛" not in y]
for i in data_list:
    print(f"今天吃{i[0]}炒{i[1]}")


vec = [2, 4, 6]
print([3*x for x in vec])
print([[x, x**2] for x in vec])
freshfruit = ['  banana', '  loganberry ', 'passion fruit  ']
print([weapon.strip() for weapon in freshfruit])
print([3*x for x in vec if x > 3])

vec1 = [2, 4, 6]
vec2 = [4, 3, -9]
print([x*y for x in vec1 for y in vec2])
print([x+y for x in vec1 for y in vec2])
print([vec1[i]*vec2[i] for i in range(len(vec1))])
print([str(round(355/113, i)) for i in range(1, 6)])

matrix = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
    [9, 10, 11, 12],
]
print([[row[i] for row in matrix] for i in range(4)])

transposed = []
for i in range(4):
    transposed.append([row[i] for row in matrix])
print(transposed)

# 相当于
transposed = []
for i in range(4):
    # the following 3 lines implement the nested listcomp
    transposed_row = []
    for row in matrix:
        transposed_row.append(row[i])
    transposed.append(transposed_row)
print(transposed)